package com.example.androidframework.ui.mall.holder

import android.annotation.SuppressLint
import android.view.View
import com.bumptech.glide.Glide
import com.example.androidframework.R
import com.example.androidframework.databinding.ItemMallGoodsTypeBinding
import com.example.androidframework.ui.mall.bean.MallGoodsTypeBean
import com.martin.lib_base.annotation.ItemData
import com.martin.lib_base.base.BaseViewHolder
import com.martin.lib_base.bean.app.mall.ParentBean
import com.martin.lib_base.interfaces.IItemData
import com.martin.lib_base.ktx.loge

@ItemData(MallGoodsTypeViewHolder.Companion.ItemData::class)
class MallGoodsTypeViewHolder(view: View) : BaseViewHolder<ParentBean, ItemMallGoodsTypeBinding>(view) {

    @SuppressLint("UseCompatLoadingForDrawables")
    override fun onBindViewHolder(position: Int, item: Any?) {
        val bean: ParentBean? = getItemBean(item)
        bean?.let {
            if (position == 9) {
                Glide.with(itemView).load(itemView.context.resources.getDrawable(R.drawable.home_more_icn, null)).into(binding.image)
                binding.title.text = "查看更多"
            } else {
                Glide.with(itemView).load(it.gc_icon).into(binding.image)
                binding.title.text = it.gc_name
            }

            itemView.setOnClickListener { item ->
                loge("点击商品分类 : ${it.gc_name}")
            }
        }
    }

    companion object {
        class ItemData: IItemData {
            override fun getItemLayoutId(): Int = R.layout.item_mall_goods_type
        }
    }
}